using System;
using System.Windows.Forms;
using RollManager.Forms.MainPanels;
using RollManager.Library;

namespace RollManager.Forms.MenuDialogs
{
    public partial class AddSubActionDialog : MenuDialog
    {
        private int m_actionId;

        private ServerGroup SelectedGroup
        {
            get
            {
                return (ServerGroup) serverGroupList.SelectedItem;
            }
        }

        public AddSubActionDialog( AdminActionsPanel panel, int actionId ) : base( panel )
        {
            m_actionId = actionId;
            InitializeComponent();

            serverGroupList.DataSource = Database.GetServerGroups();
            serverGroupList.DisplayMember = ItemBase.NAME_PROPERTY;

            permissionsList.DataSource = Enum.GetValues( typeof( Permission ) );
        }

        private void okButton_Click( object sender, EventArgs e )
        {
            SubAction s = Database.AddSubAction( nameBox.Text, m_actionId, SelectedGroup.Id, (Permission) permissionsList.SelectedValue );
            CloseAndAdd( s.Name, s );
        }

        private void cancelButton_Click( object sender, EventArgs e )
        {
            Close();
        }
    }
}